package acm.pta3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class T12 {
    /**
     * 暴力解：
     *  存储每个节点及其双亲节点。
     *  当判断两个节点时，先查看性别。
     *  而后将双方五代之内的亲戚放入两个Set集合中。
     *  通过判断两个Set集合是否有重复元素来判断是否可以通婚
     */
    public static void main(String[] args) throws IOException {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(in.readLine());
        String[] read=null;
        while (n-- > 0) {
            read=in.readLine().split(" ");
            String name=read[0];
            boolean sex="M".equals(read[1]);
            Node curr = map.getOrDefault(name, new Node(name, sex));
            map.put(name,curr);
            if (!"-1".equals(read[2])){
                Node parent = map.getOrDefault(read[2], new Node(read[2], true));
                map.put(read[2],parent);
                curr.parent=parent;
            }
            if (!"-1".equals(read[3])){
                Node mother = map.getOrDefault(read[3], new Node(read[3], false));
                map.put(read[3],mother);
                curr.mother=mother;
            }
        }
        n=Integer.parseInt(in.readLine());
        while (n-- > 0) {
            read=in.readLine().split(" ");
            Node o1 = map.get(read[0]);
            Node o2 = map.get(read[1]);
            if (o1.sex==o2.sex){
                System.out.println("Never Mind");
                continue;
            }
            System.out.println(isRelative(o1, o2)?"No":"Yes");
        }
        in.close();
    }
    static Map<String,Node> map=new HashMap<>();
    public static boolean isRelative(Node o1,Node o2){
        Set<Node> allRelative1 = getAllRelative(o1);
        Set<Node> allRelative2 = getAllRelative(o2);
        HashSet<Node> union=new HashSet<>();
        union.addAll(allRelative1);
        union.addAll(allRelative2);
        return union.size()!=allRelative1.size()+allRelative2.size();
    }


    /**
     * 获取五代之内的亲戚
     */
    public static Set<Node> getAllRelative(Node o){
        Set<Node> set=new HashSet<>();
        Queue<Node> queue=new LinkedList<>();
        Map<Node,Integer> heightMap=new HashMap<>();
        queue.add(o);
        heightMap.put(o,1);
        while (!queue.isEmpty()) {
            Node curr = queue.poll();
            Integer height = heightMap.get(curr);
            if (height>5){
                return set;
            }
            set.add(curr);
            if (curr.parent!=null) {
                queue.add(curr.parent);
                heightMap.put(curr.parent,height+1);
            }
            if (curr.mother!=null){
                queue.add(curr.mother);
                heightMap.put(curr.mother,height+1);
            }
        }
        return set;
    }

    static class Node{
        String name;
        boolean sex;
        Node parent;
        Node mother;

        public Node(String name, boolean sex) {
            this.name = name;
            this.sex = sex;
        }
    }
}
